from enum import IntEnum

from src.exts import db
from src.models.base_model import BaseModel


class PostPublishType(IntEnum):
    """文章发布类型"""
    draft = 1  # 草稿
    show = 2  # 发布


class Post(BaseModel):
    """文章类"""
    __tablename__ = "tb_post"

    id = db.Colunm(db.String(128), primary_key=True)
    title = db.Colunm(db.String(128), nullable=False)
    desc = db.Colunm(db.String(256), nullable=False)
    content = db.Colunm(db.LongText, nullable=False)
    has_type = db.Colunm(db.Enum(PostPublishType))
    category_id = db.Colunm(db.LongText, nullable=False)

    def model_to_dict(self):
        model_dict = {
            "id": self.id,
            "title": self.title,
            "desc": self.desc,
            "content": self.content,
            "category_id": self.category_id,
            "created": self.created,
            "updated": self.updated
        }

        return model_dict
